<%@page import="java.util.List"%>
<%@page import="com.mavenrentcars.model.Place"%>
<%@page import="com.mavenrentcars.form.CarForm"%>
<%@page import="java.util.HashMap"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/header.jsp" %>
<% 
	CarForm form = (CarForm) request.getAttribute("item");
    List<Place> places = (List<Place>) request.getAttribute("places");
    String json_places = (String) request.getAttribute("json_places");
%>
        <h1>Car Info</h1>
        <div>
        <table border="0">
            <tbody>
                <tr>
                    <td>
                        <div id="car_form">
                        <table border="0">
                            <tbody>
                                <tr>
                                    <td colspan="2">
                                        <input type="hidden" id="car_form_action" value="<%=form.action %>" />
                                        <input type="hidden" id="car_form_id" value="<%=form.getId() %>" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>Model:</td>
                                    <td><input type="text" id="car_form_model" value="<%=form.getModel() %>" /></td>
                                </tr>
                                <tr>
                                    <td>Output Year:</td>
                                    <td><input type="text" id="car_form_output_year" value="<%=form.getOutputYear() %>" /></td>
                                </tr>
                                                    <tr>
                                    <td>Insurance:</td>
                                    <td><input type="text" id="car_form_insurance" value="<%=form.getInsurance() %>" /></td>
                                </tr>
                                                    <tr>
                                    <td>Price:</td>
                                    <td><input type="text" id="car_form_price" value="<%=form.getPrice() %>" /></td>
                                </tr>
                                                    <tr>
                                    <td>Start Place:</td>
                                    <td>
                                        <select id="car_form_start_place">
                                        <%
                                        for(Place item : places) {
                                        %>
                                        <option <%=((form.getStartPlace().equals(item.getPlaceName())) ? "selected" : "")%> value="<%= item.getId() %>"><%= item.getPlaceName() %></option>
                                        <% } %>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <input type="submit" id="car_form_send" value="Send" />
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    </td>
                    
                    <td style="vertical-align: top;">
                        <div  id="places_list">
                            <table border="0">
                            <tbody>
                                <tr>
                                    <td colspan="2">Places:</td>
                                </tr>
                                <%
                                for(Place pitem : places) {
                                %>
                                <tr>
                                    <td><%= pitem.getPlaceName() %></td>
                                    <td>
                                        <div class="link place_action" id="place_action_<%= pitem.getId() %>"><%=((form.places.get(Integer.toString(pitem.getId())) != null) ? "delete" : "add")%></div>
                                    </td>
                                </tr>
                                <% } %>
                            </tbody>
                            </table>
                        </div>
                    </td>
                    
               </tr>
            </tbody>
        </table>
    </div>
		
		
		
	<script type="text/javascript">
		
		$(document).ready(function(){
            var carModel = new CarModel(<%=json_places%>);
			var carView = new CarView();
			var carController = new CarController(carModel, carView);
			carController.init();
		});
	</script>
    
    
<%@ include file="/WEB-INF/jsp/footer.jsp" %>